function bubble() {
    var scene = viewer.scene;

    //点击，弹出属性
    viewer.selectedEntityChanged.addEventListener(function(entity) {

        if (!spatialFlag) {
            $("#bubble").hide();

            var selectedEntity = viewer.selectedEntity;
            if (!Cesium.defined(selectedEntity) || !Cesium.defined(selectedEntity.pickResult)) {
                return;
            }
            var pickResult = selectedEntity.pickResult;
            var properties = null;

            for (var obj in pickResult) {
                var pickFeature = pickResult[obj][0].feature;
                properties = pickFeature.properties;
                break;
            }

            if (!properties) {
                return;
            }

            for (i = table.rows.length - 1; i > -1; i--) {
                table.deleteRow(i);
            }
            $("#bubble").show();

            var newRow = table.insertRow();
            var cell1 = newRow.insertCell();
            var cell2 = newRow.insertCell();
            cell1.innerHTML = "<b style='font-size: 1.00rem;'>属性</b>";
            cell2.innerHTML = "<b style='font-size: 1.00rem;'>值</b>";

            //添加图层和id信息
            var newRow = table.insertRow();
            var cell1 = newRow.insertCell();
            var cell2 = newRow.insertCell();
            cell1.innerHTML = "图层";
            cell2.innerHTML = selectedEntity.layerID;

            newRow = table.insertRow();
            var cell1 = newRow.insertCell();
            var cell2 = newRow.insertCell();
            cell1.innerHTML = "ID";
            cell2.innerHTML = selectedEntity.id;

            for (var key in properties) {
                var newRow = table.insertRow();
                var cell1 = newRow.insertCell();
                var cell2 = newRow.insertCell();
                cell1.innerHTML = key;
                cell2.innerHTML = properties[key];
            }
        }
    });

    //空间查询
    var spatialFlag = false;
    $("#spatialQuery").on("click", function() {
        spatialFlag = true;
        if (handlerPolygon.active) {
            handlerPolygon.deactivate();
        } else {
            handlerPolygon.activate();
        }
    });


    /* 气泡相关 1/4 start */
    var scenePosition = null; // 记录在场景中点击的笛卡尔坐标点
    var dock = false; // 是否停靠
    var infoboxContainer = document.getElementById("bubble");
    var table = document.getElementById("tab"); // 气泡内的表格
    $("#bubblePosition").click(function () { // 停靠状态切换
        dock = !dock;
        if ($("#bubblePosition").hasClass("fui-export")) {
            $("#bubble").removeClass("bubble").addClass("float");
            $("#bubblePosition").removeClass("fui-export").addClass("fui-bubble");
            $("#bubblePosition")[0].title = "悬浮";
            $("#bubble").css({
                'left': '82%',
                'bottom': '45%'
            });
            $("#tableContainer").css({
                'height': '350px'
            });
        } else if ($("#bubblePosition").hasClass("fui-bubble")) {
            $("#bubble").removeClass("float").addClass("bubble");
            $("#bubblePosition").removeClass("fui-bubble").addClass("fui-export");
            $("#bubblePosition")[0].title = "停靠";
            $("#tableContainer").css({
                'height': '150px'
            });
        }
    });
    $("#close").click(function () { // 关闭气泡
        $("#bubble").hide();
    });
    scene.postRender.addEventListener(function () { // 每一帧都去计算气泡的正确位置
        if (scenePosition && !dock) {
            var canvasHeight = scene.canvas.height;
            var windowPosition = new Cesium.Cartesian2();
            Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, scenePosition, windowPosition);
            infoboxContainer.style.bottom = (canvasHeight - windowPosition.y + 45) + 'px';
            infoboxContainer.style.left = (windowPosition.x - 70) + 'px';
            infoboxContainer.style.visibility = "visible";
        }
    });
    /* 气泡相关 1/4 end */

    /* 气泡相关 2/4 */
    var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
    handler.setInputAction(function (e) {
        // 获取点击位置笛卡尔坐标
        var cameraPosition = scene.camera.position;
        // 获取点击位置笛卡尔坐标
        var position = scene.pickPosition(e.position);
        scenePosition = position; // 气泡相关 2/4
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);


    /* 气泡相关 3/4 start */
    scenePosition = null;
    $("#bubble").hide();
    /* 气泡相关 3/4 end */

}